/*
Run this script on:

        mssql-tl.db.jwan.it,14444.TTTLines2013    -  This database will be modified

to synchronize it with:

        kalgan01.cs.jwan.it,1443.Jambo2014_sviluppo

You are recommended to back up your database before running this script

Script created by SQL Compare version 9.0.0 from Red Gate Software Ltd at 02/04/2014 12:11:18

*/
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Dropping foreign keys from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP
CONSTRAINT [FK_jb_categoSconti_catego1],
CONSTRAINT [FK_jb_categoSconti_sconti],
CONSTRAINT [FK_jb_categoSconti_catego2],
CONSTRAINT [FK_jb_categoSconti_jb_tessere_tipo]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_movcassabigl]'
GO
ALTER TABLE [dbo].[jb_movcassabigl] DROP
CONSTRAINT [FK_jb_movcassabigl_jb_turni],
CONSTRAINT [FK_jb_movcassabigl_causalimovim],
CONSTRAINT [FK_jb_movcassabigl_sconti],
CONSTRAINT [FK_jb_movcassabigl_catego],
CONSTRAINT [FK_jb_movcassabigl_corse],
CONSTRAINT [FK_jb_movcassabigl_itiner],
CONSTRAINT [FK_jb_movcassabigl_iva],
CONSTRAINT [FK_jb_movcassabigl_tipopagame],
CONSTRAINT [FK_jb_movcassabigl_valute],
CONSTRAINT [FK_jb_movcassabigl_jb_carrello]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_DetTax]'
GO
ALTER TABLE [dbo].[jb_DetTax] DROP
CONSTRAINT [FK_jb_DetTax_jb_movcassabigl]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_Omaggi]'
GO
ALTER TABLE [dbo].[jb_Omaggi] DROP
CONSTRAINT [FK_jb_Omaggi_jb_movcassabigl],
CONSTRAINT [FK_jb_Omaggi_macroregioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_rendiconti]'
GO
ALTER TABLE [dbo].[jb_rendiconti] DROP
CONSTRAINT [FK_jb_rendiconti_jb_movcassabigl]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_MovDettBigl]'
GO
ALTER TABLE [dbo].[jb_MovDettBigl] DROP
CONSTRAINT [FK_jb_MovDettBigl_biglie]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_postazioniMacroregioni]'
GO
ALTER TABLE [dbo].[jb_postazioniMacroregioni] DROP
CONSTRAINT [FK_jb_postazioniMacroregioni_jb_postazioniMacroregioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_postazioniOperatori]'
GO
ALTER TABLE [dbo].[jb_postazioniOperatori] DROP
CONSTRAINT [FK_jb_postazioniOperatori_jb_postazioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_PostazioniSconti]'
GO
ALTER TABLE [dbo].[jb_PostazioniSconti] DROP
CONSTRAINT [FK_jb_PostazioniSconti_jb_postazioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_stock]'
GO
ALTER TABLE [dbo].[jb_stock] DROP
CONSTRAINT [FK_jb_stock_jb_postazioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_turni]'
GO
ALTER TABLE [dbo].[jb_turni] DROP
CONSTRAINT [FK_jb_turni_jb_postazioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[operat]'
GO
ALTER TABLE [dbo].[operat] DROP
CONSTRAINT [FK_operat_jb_postazioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP
CONSTRAINT [FK_jb_postazioni_porti],
CONSTRAINT [FK_jb_postazioni_valute]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[jb_tessere]'
GO
ALTER TABLE [dbo].[jb_tessere] DROP
CONSTRAINT [FK_jb_tessere_jb_tessere_tipo]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [PK_jb_configSconti]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__GRUPP__03557281]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__QUOTA__044996BA]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__QUOTA__053DBAF3]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__QUOTA__0631DF2C]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__VOUCH__07260365]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__OMAGG__081A279E]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__CUMUL__090E4BD7]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__FORZA__0A027010]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__CTRLT__0AF69449]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__TIPO___0BEAB882]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__ORDIN__0CDEDCBB]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] DROP CONSTRAINT [DF__tmp_rg_xx__IS_PA__0DD300F4]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_movcassabigl]'
GO
ALTER TABLE [dbo].[jb_movcassabigl] DROP CONSTRAINT [PK_jb_movcassabigl]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_movcassabigl]'
GO
ALTER TABLE [dbo].[jb_movcassabigl] DROP CONSTRAINT [DF_jb_movcassabigl_ISAR_1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_movcassabigl]'
GO
ALTER TABLE [dbo].[jb_movcassabigl] DROP CONSTRAINT [DF__jb_movcas__CODCA__6F63886D]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_Omaggi]'
GO
ALTER TABLE [dbo].[jb_Omaggi] DROP CONSTRAINT [PK_Omaggi]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_Omaggi]'
GO
ALTER TABLE [dbo].[jb_Omaggi] DROP CONSTRAINT [DF__tmp_rg_xx__DATAI__2AA449CC]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_Omaggi]'
GO
ALTER TABLE [dbo].[jb_Omaggi] DROP CONSTRAINT [DF__tmp_rg_xx__UTILI__2B986E05]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [PK_Biglietterie]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__PROSS__0B95B2C7]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__NOMES__0C89D700]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__IPSTA__0D7DFB39]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__GGCOR__0E721F72]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__MMCOR__0F6643AB]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STEME__105A67E4]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STEME__114E8C1D]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STDET__1242B056]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STRIE__1336D48F]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STDET__142AF8C8]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STEME__151F1D01]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STEME__1613413A]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STRIE__17076573]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STRIE__17FB89AC]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STEME__18EFADE5]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__STBIS__19E3D21E]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] DROP CONSTRAINT [DF__jb_postaz__CODVA__1AD7F657]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[jb_tessere_tipo]'
GO
ALTER TABLE [dbo].[jb_tessere_tipo] DROP CONSTRAINT [PK_jb_tipo_abbonamenti]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping index [IX_jb_movcassabigl_postazioni_turni] from [dbo].[jb_movcassabigl]'
GO
DROP INDEX [IX_jb_movcassabigl_postazioni_turni] ON [dbo].[jb_movcassabigl]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping index [IX_jb_movcassabigl_biglietto_old] from [dbo].[jb_movcassabigl]'
GO
DROP INDEX [IX_jb_movcassabigl_biglietto_old] ON [dbo].[jb_movcassabigl]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[jb_MovDettBigl]'
GO
ALTER TABLE [dbo].[jb_MovDettBigl] DROP
COLUMN [CODPREN]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Rebuilding [dbo].[jb_movcassabigl]'
GO
CREATE TABLE [dbo].[tmp_rg_xx_jb_movcassabigl]
(
[IDPOSTAZIONE] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODTURNO] [int] NOT NULL,
[ORASECONDI] [datetime] NOT NULL,
[NUMBIGL] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[TIPOMOV] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[RIF_BIGLIETTO_OLD] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CODSCO] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CATKEY] [int] NOT NULL,
[CODCORSA_PARTENZA] [char] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CODITINERA] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[QTA] [int] NOT NULL,
[ISAR] [bit] NOT NULL DEFAULT ((0)),
[IMPORTO] [decimal] (18, 2) NOT NULL,
[IMPONIBILE] [decimal] (18, 2) NOT NULL,
[IMPOSTA] [decimal] (18, 2) NOT NULL,
[IMP_ESENTE] [decimal] (18, 2) NOT NULL,
[DIR_TAX_IMPONIBILE] [decimal] (18, 2) NOT NULL,
[DIR_TAX_IMPOSTA] [decimal] (18, 2) NOT NULL,
[CODIVA] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[FORMAPAG] [nvarchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[GRATUITI] [int] NOT NULL,
[NUM_IMBARCO] [int] NOT NULL,
[CODVAL] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
INSERT INTO [dbo].[tmp_rg_xx_jb_movcassabigl]([IDPOSTAZIONE], [CODTURNO], [ORASECONDI], [NUMBIGL], [TIPOMOV], [RIF_BIGLIETTO_OLD], [CODSCO], [CATKEY], [CODCORSA_PARTENZA], [CODITINERA], [QTA], [ISAR], [IMPORTO], [IMPONIBILE], [IMPOSTA], [IMP_ESENTE], [DIR_TAX_IMPONIBILE], [DIR_TAX_IMPOSTA], [CODIVA], [GRATUITI], [NUM_IMBARCO], [CODVAL]) SELECT [IDPOSTAZIONE], [CODTURNO], [ORASECONDI], [NUMBIGL], [TIPOMOV], [RIF_BIGLIETTO_OLD], [CODSCO], [CATKEY], [CODCORSA_PARTENZA], [CODITINERA], [QTA], [ISAR], [IMPORTO], [IMPONIBILE], [IMPOSTA], [IMP_ESENTE], [DIR_TAX_IMPONIBILE], [DIR_TAX_IMPOSTA], [CODIVA], [GRATUITI], [NUM_IMBARCO], [CODVAL] FROM [dbo].[jb_movcassabigl]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
DROP TABLE [dbo].[jb_movcassabigl]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
EXEC sp_rename N'[dbo].[tmp_rg_xx_jb_movcassabigl]', N'jb_movcassabigl'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_jb_movcassabigl] on [dbo].[jb_movcassabigl]'
GO
ALTER TABLE [dbo].[jb_movcassabigl] ADD CONSTRAINT [PK_jb_movcassabigl] PRIMARY KEY CLUSTERED  ([NUMBIGL])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_jb_movcassabigl_postazioni_turni] on [dbo].[jb_movcassabigl]'
GO
CREATE NONCLUSTERED INDEX [IX_jb_movcassabigl_postazioni_turni] ON [dbo].[jb_movcassabigl] ([IDPOSTAZIONE], [CODTURNO])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_jb_movcassabigl_biglietto_old] on [dbo].[jb_movcassabigl]'
GO
CREATE NONCLUSTERED INDEX [IX_jb_movcassabigl_biglietto_old] ON [dbo].[jb_movcassabigl] ([RIF_BIGLIETTO_OLD])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Rebuilding [dbo].[jb_categoSconti]'
GO
CREATE TABLE [dbo].[tmp_rg_xx_jb_categoSconti]
(
[CATKEY] [int] NOT NULL,
[CODSCO] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[DESCRIZIONE] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[GRUPPO] [bit] NOT NULL DEFAULT ((0)),
[QUOTA_GUIDA] [int] NOT NULL DEFAULT ((0)),
[SCONTO_GUIDA] [decimal] (18, 2) NOT NULL DEFAULT ((0)),
[QUOTA_PAX] [int] NOT NULL DEFAULT ((0)),
[CATKEY_PAX] [int] NULL,
[VOUCHER] [bit] NOT NULL DEFAULT ((0)),
[OMAGGIO] [bit] NOT NULL DEFAULT ((0)),
[CTRLTKT] [bit] NOT NULL DEFAULT ((0)),
[TIPO_TESSERA] [int] NULL DEFAULT ((0)),
[ORDINE] [int] NOT NULL DEFAULT ((0)),
[IS_PASSAGGIO_TESSERA] [bit] NOT NULL DEFAULT ((0)),
[RESIDENTE] [bit] NOT NULL DEFAULT ((0))
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
INSERT INTO [dbo].[tmp_rg_xx_jb_categoSconti]([CATKEY], [CODSCO], [DESCRIZIONE], [GRUPPO], [QUOTA_GUIDA], [QUOTA_PAX], [CATKEY_PAX], [VOUCHER], [OMAGGIO], [CTRLTKT], [TIPO_TESSERA], [ORDINE]) SELECT [CATKEY], [CODSCO], [DESCRIZIONE], [GRUPPO], [QUOTA_GUIDA], [QUOTA_PAX], [CATKEY_PAX], [VOUCHER], [OMAGGIO], [CTRLTKT], [TIPO_TESSERA], [ORDINE] FROM [dbo].[jb_categoSconti]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
DROP TABLE [dbo].[jb_categoSconti]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
EXEC sp_rename N'[dbo].[tmp_rg_xx_jb_categoSconti]', N'jb_categoSconti'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_jb_configSconti] on [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] ADD CONSTRAINT [PK_jb_configSconti] PRIMARY KEY CLUSTERED  ([CATKEY], [CODSCO])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Rebuilding [dbo].[jb_postazioni]'
GO
CREATE TABLE [dbo].[tmp_rg_xx_jb_postazioni]
(
[IDPOSTAZIONE] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[DESCRIZIONE] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[PROSSIMAFATT] [smallint] NOT NULL,
[PROSSIMOTURNO] [int] NOT NULL DEFAULT ((1)),
[CODCOMP] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[IPSTAMPANTE] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL DEFAULT ('192.168.0.1:9100'),
[GGCORSEAND] [int] NOT NULL DEFAULT ((10)),
[MINUTI_TOLLERANZA] [int] NOT NULL DEFAULT ((90)),
[CODPORTO] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[BLOCCOOVERPAX] [bit] NULL,
[BLOCCOOVERVEI] [bit] NULL,
[CODVAL] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL DEFAULT (N'EUR'),
[CODITINERA] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[COD_LOCALE] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
INSERT INTO [dbo].[tmp_rg_xx_jb_postazioni]([IDPOSTAZIONE], [DESCRIZIONE], [PROSSIMAFATT], [PROSSIMOTURNO], [IPSTAMPANTE], [GGCORSEAND], [CODPORTO], [BLOCCOOVERPAX], [BLOCCOOVERVEI], [CODVAL]) SELECT [IDPOSTAZIONE], [DESCRIZIONE], [PROSSIMAFATT], [PROSSIMOTURNO], [IPSTAMPANTE], [GGCORSEAND], [CODPORTO], [BLOCCOOVERPAX], [BLOCCOOVERVEI], [CODVAL] FROM [dbo].[jb_postazioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
DROP TABLE [dbo].[jb_postazioni]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
EXEC sp_rename N'[dbo].[tmp_rg_xx_jb_postazioni]', N'jb_postazioni'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_Biglietterie] on [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] ADD CONSTRAINT [PK_Biglietterie] PRIMARY KEY CLUSTERED  ([IDPOSTAZIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Rebuilding [dbo].[jb_Omaggi]'
GO
CREATE TABLE [dbo].[tmp_rg_xx_jb_Omaggi]
(
[CODOMAGGIO] [varchar] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[DATAINIZIO] [datetime] NOT NULL DEFAULT (getdate()),
[DATAFINE] [datetime] NOT NULL,
[MACROREGIONE] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[NOTE] [char] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[RILASCIO] [datetime] NULL,
[UTILIZZATO] [bit] NOT NULL DEFAULT ((0)),
[NUMBIGL] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
INSERT INTO [dbo].[tmp_rg_xx_jb_Omaggi]([DATAINIZIO], [DATAFINE], [MACROREGIONE], [NOTE], [RILASCIO], [UTILIZZATO], [NUMBIGL]) SELECT [DATAINIZIO], [DATAFINE], [MACROREGIONE], [NOTE], [RILASCIO], [UTILIZZATO], [NUMBIGL] FROM [dbo].[jb_Omaggi]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
DROP TABLE [dbo].[jb_Omaggi]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
EXEC sp_rename N'[dbo].[tmp_rg_xx_jb_Omaggi]', N'jb_Omaggi'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_Omaggi] on [dbo].[jb_Omaggi]'
GO
ALTER TABLE [dbo].[jb_Omaggi] ADD CONSTRAINT [PK_Omaggi] PRIMARY KEY CLUSTERED  ([CODOMAGGIO])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Rebuilding [dbo].[jb_tessere_tipo]'
GO
CREATE TABLE [dbo].[tmp_rg_xx_jb_tessere_tipo]
(
[TIPO_TESSERA] [int] NOT NULL IDENTITY(1, 1),
[DESCRIZIONE] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[PERCORSO_LIBERO] [bit] NOT NULL DEFAULT ((0))
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
SET IDENTITY_INSERT [dbo].[tmp_rg_xx_jb_tessere_tipo] ON
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
INSERT INTO [dbo].[tmp_rg_xx_jb_tessere_tipo]([TIPO_TESSERA], [DESCRIZIONE]) SELECT [TIPO_TESSERA], [DESCRIZIONE] FROM [dbo].[jb_tessere_tipo]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
SET IDENTITY_INSERT [dbo].[tmp_rg_xx_jb_tessere_tipo] OFF
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
DROP TABLE [dbo].[jb_tessere_tipo]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
EXEC sp_rename N'[dbo].[tmp_rg_xx_jb_tessere_tipo]', N'jb_tessere_tipo'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_jb_tipo_abbonamenti] on [dbo].[jb_tessere_tipo]'
GO
ALTER TABLE [dbo].[jb_tessere_tipo] ADD CONSTRAINT [PK_jb_tipo_abbonamenti] PRIMARY KEY CLUSTERED  ([TIPO_TESSERA])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[jb_etichette]'
GO
ALTER TABLE [dbo].[jb_etichette] ALTER COLUMN [DESCRIZIONE] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_categoSconti]'
GO
ALTER TABLE [dbo].[jb_categoSconti] ADD
CONSTRAINT [FK_jb_categoSconti_catego1] FOREIGN KEY ([CATKEY]) REFERENCES [dbo].[catego] ([CATKEY]),
CONSTRAINT [FK_jb_categoSconti_sconti] FOREIGN KEY ([CODSCO]) REFERENCES [dbo].[sconti] ([CODSCO]),
CONSTRAINT [FK_jb_categoSconti_catego2] FOREIGN KEY ([CATKEY_PAX]) REFERENCES [dbo].[catego] ([CATKEY]),
CONSTRAINT [FK_jb_categoSconti_jb_tessere_tipo] FOREIGN KEY ([TIPO_TESSERA]) REFERENCES [dbo].[jb_tessere_tipo] ([TIPO_TESSERA])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_movcassabigl]'
GO
ALTER TABLE [dbo].[jb_movcassabigl] ADD
CONSTRAINT [FK_jb_movcassabigl_jb_turni] FOREIGN KEY ([IDPOSTAZIONE], [CODTURNO]) REFERENCES [dbo].[jb_turni] ([IDPOSTAZIONE], [CODTURNO]),
CONSTRAINT [FK_jb_movcassabigl_causalimovim] FOREIGN KEY ([TIPOMOV]) REFERENCES [dbo].[causalimovim] ([TIPOMOV]),
CONSTRAINT [FK_jb_movcassabigl_sconti] FOREIGN KEY ([CODSCO]) REFERENCES [dbo].[sconti] ([CODSCO]),
CONSTRAINT [FK_jb_movcassabigl_catego] FOREIGN KEY ([CATKEY]) REFERENCES [dbo].[catego] ([CATKEY]),
CONSTRAINT [FK_jb_movcassabigl_corse] FOREIGN KEY ([CODCORSA_PARTENZA]) REFERENCES [dbo].[corse] ([CODCORSA]),
CONSTRAINT [FK_jb_movcassabigl_itiner] FOREIGN KEY ([CODITINERA]) REFERENCES [dbo].[itiner] ([CODITINERA]),
CONSTRAINT [FK_jb_movcassabigl_iva] FOREIGN KEY ([CODIVA]) REFERENCES [dbo].[iva] ([CODIVA]),
CONSTRAINT [FK_jb_movcassabigl_pagame] FOREIGN KEY ([FORMAPAG]) REFERENCES [dbo].[pagame] ([FORMAPAG]),
CONSTRAINT [FK_jb_movcassabigl_valute] FOREIGN KEY ([CODVAL]) REFERENCES [dbo].[valute] ([CODVAL])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_DetTax]'
GO
ALTER TABLE [dbo].[jb_DetTax] ADD
CONSTRAINT [FK_jb_DetTax_jb_movcassabigl] FOREIGN KEY ([NUMBIGL]) REFERENCES [dbo].[jb_movcassabigl] ([NUMBIGL])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_Omaggi]'
GO
ALTER TABLE [dbo].[jb_Omaggi] ADD
CONSTRAINT [FK_jb_Omaggi_jb_movcassabigl] FOREIGN KEY ([NUMBIGL]) REFERENCES [dbo].[jb_movcassabigl] ([NUMBIGL]),
CONSTRAINT [FK_jb_Omaggi_macroregioni] FOREIGN KEY ([MACROREGIONE]) REFERENCES [dbo].[macroregioni] ([MACROREGIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_rendiconti]'
GO
ALTER TABLE [dbo].[jb_rendiconti] ADD
CONSTRAINT [FK_jb_rendiconti_jb_movcassabigl] FOREIGN KEY ([NUMBIGL]) REFERENCES [dbo].[jb_movcassabigl] ([NUMBIGL])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_postazioniMacroregioni]'
GO
ALTER TABLE [dbo].[jb_postazioniMacroregioni] ADD
CONSTRAINT [FK_jb_postazioniMacroregioni_jb_postazioniMacroregioni] FOREIGN KEY ([IDPOSTAZIONE]) REFERENCES [dbo].[jb_postazioni] ([IDPOSTAZIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_postazioniOperatori]'
GO
ALTER TABLE [dbo].[jb_postazioniOperatori] ADD
CONSTRAINT [FK_jb_postazioniOperatori_jb_postazioni] FOREIGN KEY ([IDPOSTAZIONE]) REFERENCES [dbo].[jb_postazioni] ([IDPOSTAZIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_PostazioniSconti]'
GO
ALTER TABLE [dbo].[jb_PostazioniSconti] ADD
CONSTRAINT [FK_jb_PostazioniSconti_jb_postazioni] FOREIGN KEY ([IDPOSTAZIONE]) REFERENCES [dbo].[jb_postazioni] ([IDPOSTAZIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_stock]'
GO
ALTER TABLE [dbo].[jb_stock] ADD
CONSTRAINT [FK_jb_stock_jb_postazioni] FOREIGN KEY ([IDPOSTAZIONE]) REFERENCES [dbo].[jb_postazioni] ([IDPOSTAZIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_turni]'
GO
ALTER TABLE [dbo].[jb_turni] ADD
CONSTRAINT [FK_jb_turni_jb_postazioni] FOREIGN KEY ([IDPOSTAZIONE]) REFERENCES [dbo].[jb_postazioni] ([IDPOSTAZIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[operat]'
GO
ALTER TABLE [dbo].[operat] ADD
CONSTRAINT [FK_operat_jb_postazioni] FOREIGN KEY ([IDPOSTAZIONE]) REFERENCES [dbo].[jb_postazioni] ([IDPOSTAZIONE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_postazioni]'
GO
ALTER TABLE [dbo].[jb_postazioni] ADD
CONSTRAINT [FK_jb_postazioni_compagnie] FOREIGN KEY ([CODCOMP]) REFERENCES [dbo].[compagnie] ([CODCOMP]),
CONSTRAINT [FK_jb_postazioni_porti] FOREIGN KEY ([CODPORTO]) REFERENCES [dbo].[porti] ([CODPORTO]),
CONSTRAINT [FK_jb_postazioni_valute] FOREIGN KEY ([CODVAL]) REFERENCES [dbo].[valute] ([CODVAL]),
CONSTRAINT [FK_jb_postazioni_itiner] FOREIGN KEY ([CODITINERA]) REFERENCES [dbo].[itiner] ([CODITINERA]),
CONSTRAINT [FK_jb_postazioni_bknloc] FOREIGN KEY ([COD_LOCALE]) REFERENCES [dbo].[bknloc] ([COD_LOCALE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_tessere]'
GO
ALTER TABLE [dbo].[jb_tessere] ADD
CONSTRAINT [FK_jb_tessere_jb_tessere_tipo] FOREIGN KEY ([TIPO_TESSERA]) REFERENCES [dbo].[jb_tessere_tipo] ([TIPO_TESSERA])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating extended properties'
GO
EXEC sp_addextendedproperty N'MS_Description', N'associa l''eventuale categoria pax ad un''altra categoria (es. auto con autista)', 'SCHEMA', N'dbo', 'TABLE', N'jb_categoSconti', 'COLUMN', N'CATKEY_PAX'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
EXEC sp_addextendedproperty N'MS_Description', N'indica i minuti di tolleranza in TT per recuperare le corse passate', 'SCHEMA', N'dbo', 'TABLE', N'jb_postazioni', 'COLUMN', N'MINUTI_TOLLERANZA'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering permissions on [dbo].[jb_categoSconti]'
GO
GRANT SELECT ON  [dbo].[jb_categoSconti] TO [JamboClient]
GRANT SELECT ON  [dbo].[jb_categoSconti] TO [JamboGest]
GRANT INSERT ON  [dbo].[jb_categoSconti] TO [JamboGest]
GRANT DELETE ON  [dbo].[jb_categoSconti] TO [JamboGest]
GRANT UPDATE ON  [dbo].[jb_categoSconti] TO [JamboGest]
GO
PRINT N'Altering permissions on [dbo].[jb_movcassabigl]'
GO
GRANT SELECT ON  [dbo].[jb_movcassabigl] TO [JamboClient]
GRANT INSERT ON  [dbo].[jb_movcassabigl] TO [JamboClient]
GRANT DELETE ON  [dbo].[jb_movcassabigl] TO [JamboClient]
GRANT UPDATE ON  [dbo].[jb_movcassabigl] TO [JamboClient]
GRANT SELECT ON  [dbo].[jb_movcassabigl] TO [JamboGest]
GRANT INSERT ON  [dbo].[jb_movcassabigl] TO [JamboGest]
GRANT DELETE ON  [dbo].[jb_movcassabigl] TO [JamboGest]
GRANT UPDATE ON  [dbo].[jb_movcassabigl] TO [JamboGest]
GO
PRINT N'Altering permissions on [dbo].[jb_Omaggi]'
GO
GRANT SELECT ON  [dbo].[jb_Omaggi] TO [JamboClient]
GRANT INSERT ON  [dbo].[jb_Omaggi] TO [JamboClient]
GRANT DELETE ON  [dbo].[jb_Omaggi] TO [JamboClient]
GRANT UPDATE ON  [dbo].[jb_Omaggi] TO [JamboClient]
GRANT SELECT ON  [dbo].[jb_Omaggi] TO [JamboGest]
GRANT INSERT ON  [dbo].[jb_Omaggi] TO [JamboGest]
GRANT DELETE ON  [dbo].[jb_Omaggi] TO [JamboGest]
GRANT UPDATE ON  [dbo].[jb_Omaggi] TO [JamboGest]
GO
PRINT N'Altering permissions on [dbo].[jb_postazioni]'
GO
GRANT SELECT ON  [dbo].[jb_postazioni] TO [JamboClient]
GRANT INSERT ON  [dbo].[jb_postazioni] TO [JamboClient]
GRANT DELETE ON  [dbo].[jb_postazioni] TO [JamboClient]
GRANT UPDATE ON  [dbo].[jb_postazioni] TO [JamboClient]
GRANT SELECT ON  [dbo].[jb_postazioni] TO [JamboGest]
GRANT INSERT ON  [dbo].[jb_postazioni] TO [JamboGest]
GRANT DELETE ON  [dbo].[jb_postazioni] TO [JamboGest]
GRANT UPDATE ON  [dbo].[jb_postazioni] TO [JamboGest]
GO
PRINT N'Altering permissions on [dbo].[jb_tessere_tipo]'
GO
GRANT SELECT ON  [dbo].[jb_tessere_tipo] TO [JamboClient]
GRANT SELECT ON  [dbo].[jb_tessere_tipo] TO [JamboGest]
GRANT INSERT ON  [dbo].[jb_tessere_tipo] TO [JamboGest]
GRANT DELETE ON  [dbo].[jb_tessere_tipo] TO [JamboGest]
GRANT UPDATE ON  [dbo].[jb_tessere_tipo] TO [JamboGest]
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO
